package com.weixin.paleituo.adapter;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.weixin.paleituo.R;
import com.weixin.paleituo.base.ActivityLifeCycleEvent;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.MessageBean;
import com.weixin.paleituo.help.RecycleViewHolder;

import java.util.List;

import io.reactivex.subjects.PublishSubject;

/**
 * Author yichao
 * Time  2017/12/1 0:38
 * Dest  我的消息
 */

public class MyMessageRecyclerViewAdapter extends BaseRecycleAdapter<MessageBean> {


    private ImageView mImageViewIcon;
    private TextView mTvTitle;
    private TextView mTvContent;
    private TextView mTvTime;
    private List<MessageBean> mMStringList;
    private PublishSubject<ActivityLifeCycleEvent> mLifecycleSubject;
    private SwipeMenuLayout mSwipeMenuLayout;
    private Dialog mLoadingDialog;
    private LinearLayout mLinearLayout;

    public MyMessageRecyclerViewAdapter(Context context, List<MessageBean> mStringList, PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        super(context,mStringList,R.layout.layout_my_message);

        mMStringList = mStringList;
        mLifecycleSubject = lifecycleSubject;
    }

    @Override
    protected void setData(final RecycleViewHolder holder,final MessageBean messageBean,final int position) {

        mImageViewIcon = holder.getItemView(R.id.iv_icon_layout_item_mymessage);
        mTvTitle = holder.getItemView(R.id.tv_title_layout_my_message);
        mTvContent = holder.getItemView(R.id.tv_content_layout_my_message);
        mTvTime = holder.getItemView(R.id.tv_time_layout_my_message);
        Button  btDelte = holder.getItemView(R.id.btnDelete);
        mLinearLayout = holder.getItemView(R.id.ll_item_content_message_details_activity);

        if (messageBean.getType()==1){
            //系统
            mImageViewIcon.setImageResource(R.mipmap.xitong);
        }else if (messageBean.getType()==2){
            mImageViewIcon.setImageResource(R.mipmap.dongtai);
        } else if (messageBean.getType()==3){

            mImageViewIcon.setImageResource(R.mipmap.promotion);
        }else if (messageBean.getType()==4){

            mImageViewIcon.setImageResource(R.mipmap.yongjin);
        }

        mTvTitle.setText(messageBean.getTitle()+"");
        mTvTime.setText(messageBean.getNewsTime()+"");
        mTvContent.setText(messageBean.getContent()+"");
        mLinearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener!=null){

                mOnItemClickListener.onClick(v,position,messageBean);
                }
            }
        });


        btDelte.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (mOnItemClickListener!=null){
                    mOnItemClickListener.onDelete(v,holder,messageBean,position);
                }





            }
        });

    }





private OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener{
    void onClick(View v, int position, MessageBean messageBean);
    void onDelete(View v,RecycleViewHolder holder,final MessageBean messageBean,final int position);


    }
public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener=onItemClickListener;

}

}
